package io.github.lee.jel.ui.main

import androidx.annotation.DrawableRes
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import io.github.lee.jel.R
import io.github.lee.jel.ui.main.home.HomeFragment
import io.github.lee.jel.ui.main.media.MainMediaFragment


class MainPageAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {

    private val fragments = mutableMapOf<Int, Pair<Int, Fragment>>(
        0 to (R.drawable.outline_home_24 to HomeFragment.newInstance()),
        1 to (R.drawable.baseline_perm_media_24 to MainMediaFragment.newInstance())
    )

    override fun getItemCount(): Int = 2


    override fun createFragment(position: Int): Fragment =
        fragments[position]?.second
            ?: throw IndexOutOfBoundsException("The main page badge index is up to $itemCount")

    @DrawableRes
    fun getIcon(position: Int): Int =
        fragments[position]?.first ?: throw IndexOutOfBoundsException(
            "The main page badge index is up to $itemCount"
        )

}